﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.css.transitions {
    import flash.events.*;
    import reprise.commands.*;
    import flash.display.*;
    import reprise.data.*;

    public class CSSMovieClipController extends AbstractAsynchronousCommand {

        protected var m_frameDelayCount:int;// = 0
        protected var m_operation:String;
        protected var m_resetOnExecute:Boolean;// = false
        protected var m_operationParameters:Array;
        protected var m_frameRange:Range;
        protected var m_target:MovieClip;
        protected var m_frameDelay:int;// = 1
        protected var m_direction:int;// = 1
        protected var m_playedLoops:int;
        protected var m_loops:int;

        public static const DIRECTION_BACKWARDS:int = -1;
        public static const DIRECTION_FORWARDS:int = 1;

        public function CSSMovieClipController(_arg1:MovieClip){
            setTarget(_arg1);
        }
        override public function cancel():void{
            m_target.removeEventListener(Event.ENTER_FRAME, target_enterFrame);
            super.cancel();
        }
        public function stop(_arg1=NaN):void{
        }
        protected function target_enterFrame(_arg1:Event):void{
            if (++m_frameDelayCount < m_frameDelay){
                return;
            };
            m_frameDelayCount = 0;
            if (m_operation == "stop"){
                notifyComplete(true);
                return;
            };
            if (currentFrame() != (m_frameRange.location + m_frameRange.length)){
                m_target.gotoAndStop((currentFrame() + (1 * m_direction)));
                if (((!((((currentFrame() == (m_frameRange.location + m_frameRange.length))) && ((m_frameDelay == 1))))) || ((m_playedLoops < (m_loops - 1))))){
                    return;
                };
            };
            if (++m_playedLoops < m_loops){
                if (m_operation == "loop"){
                    m_target.gotoAndStop(m_frameRange.location);
                } else {
                    if (m_operation == "marquee"){
                        m_frameRange.location = currentFrame();
                        m_frameRange.length = (m_frameRange.length * -1);
                        m_direction = (m_direction * -1);
                        m_target.gotoAndStop((currentFrame() + (1 * m_direction)));
                    };
                };
                return;
            };
            notifyComplete(true);
        }
        public function gotoAndPlay(_arg1:int):void{
            _arg1 = normalizedFrame(_arg1);
            m_target.gotoAndStop(_arg1);
            execute();
        }
        public function totalFrames():int{
            return (m_target.totalFrames);
        }
        public function setDirection(_arg1:int):void{
            m_direction = _arg1;
        }
        override protected function notifyComplete(_arg1:Boolean):void{
            m_target.removeEventListener(Event.ENTER_FRAME, target_enterFrame);
            super.notifyComplete(_arg1);
        }
        public function setFrameRange(_arg1:Range):void{
            m_frameRange = _arg1.clone();
            m_frameRange.location = Math.max(1, m_frameRange.location);
            m_frameRange.length = ((Math.min(totalFrames(), ((m_frameRange.location + m_frameRange.length) - 1)) - m_frameRange.location) + 1);
            m_direction = ((m_frameRange.length < 0)) ? DIRECTION_BACKWARDS : DIRECTION_FORWARDS;
            if (isExecuting()){
                applyFrameRange();
            };
        }
        public function setTarget(_arg1:MovieClip):void{
            m_target = _arg1;
            if (m_frameRange == null){
                m_frameRange = new Range(1, _arg1.totalFrames);
            };
        }
        public function gotoAndStop(_arg1:int):void{
            _arg1 = normalizedFrame(_arg1);
            m_target.gotoAndStop(_arg1);
        }
        public function frameRange():Range{
            return (m_frameRange.clone());
        }
        public function setFrameDelay(_arg1:int):void{
            m_frameDelay = Math.max(0, _arg1);
        }
        protected function applyFrameRange():void{
            m_target.gotoAndStop(m_frameRange.location);
        }
        protected function applyOperation():void{
            var _local2:int;
            var _local3:int;
            var _local1:Array = m_target.currentLabels;
            switch (m_operation){
                case "play":
                case "loop":
                case "marquee":
                    m_loops = 1;
                    m_playedLoops = 0;
                    if (((!(m_operationParameters)) || ((m_operationParameters.length == 0)))){
                        _local2 = currentFrame();
                        _local3 = totalFrames();
                    } else {
                        if (m_operationParameters.length == 1){
                            _local3 = absolutizeFrame(m_operationParameters[0], _local1);
                            _local2 = (currentFrame() + (1 * (((_local3 > currentFrame())) ? 1 : -1)));
                        } else {
                            _local2 = absolutizeFrame(m_operationParameters[0], _local1);
                            _local3 = absolutizeFrame(m_operationParameters[1], _local1);
                            if ((((m_operationParameters.length > 2)) && ((((m_operation == "loop")) || ((m_operation == "marquee")))))){
                                m_loops = m_operationParameters[2];
                                if (m_loops == 0){
                                    m_loops = (int.MAX_VALUE / 2);
                                };
                            };
                            if (m_operation == "marquee"){
                                m_loops = (m_loops * 2);
                            };
                        };
                    };
                    if (_local2 == 0){
                        _local2++;
                    };
                    setFrameRange(new Range(_local2, (_local3 - _local2)));
                    break;
                case "stop":
                    m_target.gotoAndStop(((((m_operationParameters) && (m_operationParameters[0]))) || (m_target.currentFrame)));
                    break;
                default:
                    throw (new Error(("CSSMovieClipController operation not supported: " + m_operation)));
            };
        }
        public function loop(_arg1:int, _arg2:int, _arg3:int=0):void{
        }
        public function setOperation(_arg1:String, _arg2:Array):void{
            m_operation = _arg1;
            m_operationParameters = _arg2;
        }
        protected function absolutizeFrame(_arg1, _arg2:Array):int{
            var _local3:FrameLabel;
            if ((_arg1 is int)){
                return (_arg1);
            };
            if ("+-".indexOf(_arg1.charAt(0)) != -1){
                return ((currentFrame() + parseInt(_arg1)));
            };
            for each (_local3 in _arg2) {
                if (_local3.name == _arg1){
                    return (_local3.frame);
                };
            };
            return (1);
        }
        public function marquee(_arg1:int, _arg2:int, _arg3:int=0):void{
        }
        public function setResetsOnExecute(_arg1:Boolean):void{
            m_resetOnExecute = _arg1;
        }
        public function currentFrame():int{
            return (m_target.currentFrame);
        }
        protected function normalizedFrame(_arg1:int):int{
            _arg1 = Math.max(_arg1, m_frameRange.location);
            _arg1 = Math.min(_arg1, ((m_frameRange.location + m_frameRange.length) - 1));
            return (_arg1);
        }
        public function resetsOnExecute():Boolean{
            return (m_resetOnExecute);
        }
        public function play(_arg1=NaN, _arg2=NaN):void{
        }
        override public function execute(... _args):void{
            super.execute();
            m_target.addEventListener(Event.ENTER_FRAME, target_enterFrame, false, 0, true);
            if (m_operation){
                applyOperation();
                return;
            };
            if (m_resetOnExecute){
                if (m_direction == DIRECTION_FORWARDS){
                    gotoAndStop(m_frameRange.location);
                } else {
                    gotoAndStop(((m_frameRange.location + m_frameRange.length) - 1));
                };
            } else {
                applyFrameRange();
            };
        }

    }
}//package reprise.css.transitions 
